#! /usr/bin/python

debug = False

f_out	= open("exacto.out",'r')
f_in	= open("rnd.in",'r')

l	= map(int,f_in.readline().strip().split())
c	= l[0]
v	= l[1]

while c!=-1 and v!=-1:

	if debug: print "# clausulas",c
	if debug: print "# variables",v

	# parseo el out

	num_claus_sat	= int(f_out.readline().strip().split()[0])
	claus_sat		= set(map(int,f_out.readline().strip().split()[1:]))
	var_true		= set(map(int,f_out.readline().strip().split()[1:]))

	if debug: print "# de clausulas satisfechas:",num_claus_sat
	if debug: print "clausulas satisfechas:",claus_sat
	if debug: print "variables verdaderas:",var_true

	# parseo el in

	for i in range(1,c+1):
		claus = map(int,f_in.readline().strip().split())[1:]
		if debug: print "	clausula",i,claus
		for j in claus:
			if (j<0 and j not in var_true) or (j>0 and j in var_true):
				# en vez de discard usar remove pero hay que tocar un par de cosas
				claus_sat.discard(i)
				break

	if debug: print "claus_sat al final:",claus_sat,"\n"

	if(claus_sat): print "MAL"
	else: print "OK"

	l	= map(int,f_in.readline().strip().split())
	c	= l[0]
	v	= l[1]

f_in.close()
f_out.close()
